package com.growthserver.kafkaMQ;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.growthserver.param.IntegralParam;
import com.growthserver.service.AppletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 行为动作接受
 * 进行规则判断
 */
@Component
public class receiveActiveConsumer {

    private final Logger LOGGER = LoggerFactory.getLogger(receiveActiveConsumer.class);

    @Autowired
    private AppletService appletService;


    @Transactional(rollbackFor = Exception.class)
    @KafkaListener(topics = "${internalTypeConsumerTopic:TOPIC_INTERNAL}", groupId = "${kafkaGroupId:KAFKA_GROUP_INTERFACE_GROWTH1}")
    public void internalGrowthConsumer(String message) {
        LOGGER.info("进行积分明细数据入库操作消费:{}", message);
        IntegralParam integralParam = new IntegralParam();
        JSONObject jsonObject = JSON.parseObject(message);
        integralParam.setUserId(jsonObject.getString("userId"));
        integralParam.setType(jsonObject.getString("type"));
        appletService.growthRules(integralParam);

    }
}
